﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DTO;

namespace BLL
{
    public class DiemThanhPhanBLL
    {
        static int id = 0;
        QuanLyDiemDataContext DB = new QuanLyDiemDataContext();
        public IQueryable SelectDes()
        {
            return DB.DiemThanhPhans.OrderByDescending(s => s.MaTP).AsQueryable();
        }
        public string Insert(DiemThanhPhanDTO diemtpdto)
        {
            try
            {
                DiemThanhPhan nk = new DiemThanhPhan();
                nk.MaTP= (id++).ToString();
                nk.TenThanhPhan = diemtpdto.TenThanhPhan; 
                nk.HeSo = diemtpdto.Heso;
                DB.DiemThanhPhans.InsertOnSubmit(nk);
                DB.SubmitChanges();
                return "Thanh cong";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        public string Update(DiemThanhPhanDTO diemtpdto)
        {
            try
            {
                DiemThanhPhan nk = DB.DiemThanhPhans.Where(s => s.MaTP == diemtpdto.MaTP).FirstOrDefault();
                nk.TenThanhPhan = diemtpdto.TenThanhPhan;
                nk.HeSo = diemtpdto.Heso;
                DB.SubmitChanges();
                return "Thanh cong";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        public string Delete()
        {
            try
            {


                DB.SubmitChanges();
                return "Thanh cong";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

    }
}
